//document.execCommand("BackgroundImageCache", false, true);

//初始函数
var thew = null;//以下三个为判断页面是否需要刷新的参数变量,长,宽,隐藏
var theh = null;
var thehidded = null;

var xmlHttp; //为系统其他操作所用
var xmlHttps;//为计数器所用
//创建xmlHttp,xmlHttps实例
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}
function createXMLHttpsRequest() {
	if (window.ActiveXObject) {
		xmlHttps = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest) {
		xmlHttps = new XMLHttpRequest();
	}
}

//定期调整页面尺寸函数
var tree = document.getElementById("tree");
var navbar = document.getElementById("navbar");
var tag = document.getElementById("tag");
function initDe(c) {
	var w = document.body.clientWidth;
	var h = document.body.clientHeight;
	if(!hidded && thew != w-232 || hidded && thew != w-12 || theh != h-135 || thehidded!=hidded || c!=0){
		var maindiv = document.getElementById(nowdiv);
		var operate = document.getElementById(nowdiv+"_operate");
		var shade = document.getElementById(nowdiv+"_shade");
		//初始化
		if (hidded){
			thew = w-12;
		}else{
			thew = w-232;
		}
		theh = h-135;
		thehidded = hidded;
		
		//开始调整
		navbar.style.height=h-100;//调整navbar长
		tag.style.width=thew;//调整标签长
		maindiv.style.width=thew;//调整主页面长宽
		maindiv.style.height=h-135;
		if(shade!=null){//调整遮罩长宽
			shade.style.width=thew;
			shade.style.height=h-206;
		}
		if(operate!=null){//调整操作层长
			operate.style.width=thew;
		}
		
		if(c!=0){//如果是切换窗口
			var num;
			var hei;
			if(c=="find"){
				num=4;
				hei=229;
			}else if(c=="firstpage"){
				num=2;
				hei=207;
			}else if(c=="about"){
				num=2;
				hei=207;
			}else{
				num=5;
				hei=351;
			}
			if(document.getElementById(c)!=null){
				var a = document.getElementById(c).getElementsByTagName("div");
				if(a.length-1<num){
					setTimeout("initDe('"+c+"')",100);
				}else{
						a[num].style.height=h-hei;
				}
			}
		}else{//如果是窗口变化大小
			var num;
			var hei;
			if(nowdiv=="find"){
				num=4;
				hei=229;
			}else if(nowdiv=="firstpage"){
				num=2;
				hei=207;
			}else if(nowdiv=="about"){
				num=2;
				hei=207;
			}else{
				num=5;
				hei=351;
			}
			var a = document.getElementById(nowdiv).getElementsByTagName("div");
			if(a.length-1<num){
				setTimeout("initDe('"+c+"')",100);
			}else{
					a[num].style.height=h-hei;
			}
		}
		if(searchhidded){
			tree.style.height=h-109;
		}else{
			tree.style.height=h-135;
		}
		adjusttagwidth();
	}
}
setInterval("initDe(0)",500);

//增加主页logo
function addlogo(){
	var h=document.getElementById("topleft");
	var i=document.createElement("img");
	i.src="/javascripts/dep_manage/images/logo0.jpg";
	i.title="首页";
	i.border=0;
	i.style.cursor="pointer";
	i.onclick= new Function("switchtag('firstpage')");
	h.appendChild(i);
}
addlogo();

//增加搜索输入框
function addthesearch(){
	var h=document.getElementById("searchbar");
	var i=document.createElement("input");
	i.id="thesearch";
	i.type="text";
	i.className="input";
	i.onfocus= new Function("showH('1')");
	i.onblur= new Function("showH('0')");
	i.onkeyup= new Function("find()");
	h.appendChild(i);
}
addthesearch();

//增加搜索按钮
function addnavbar0(){
	var h=document.getElementById("navbar0");
	var i=document.createElement("img");
	i.id="arrowpic1";
	i.src="/javascripts/dep_manage/images/arrow1.gif";
	i.title="隐藏搜索";
	i.onclick= new Function("hidesearch()");
	h.appendChild(i);
}
addnavbar0();

//增加树按钮
function addnavbar(){
	var h=document.getElementById("navbar");
	var i=document.createElement("img");
	i.id="arrowpic2";
	i.src="/javascripts/dep_manage/images/arrow2.gif";
	i.title="隐藏树";
	i.onclick= new Function("hidetree()");
	i.align="absmiddle";
	h.appendChild(i);
}
addnavbar();

//增加标签list
function addtablist(){
	var h=document.getElementById("content");
	var i=CreateEl("div","tablist","tablist");
	i.onclick= new Function("showtaglist(this)");
	i.onmouseover= new Function("tablistaddbk(this)");
	i.onmouseout= new Function("tablistmovebk(this)");
	i.onmousedown= new Function("tablistdownbk(this)");
	i.onmouseup= new Function("tablistupbk(this)");
	var m=CreateEl("div","tablist_l","tablist_1");
	var n=CreateEl("div","tablist_r","tablist_r");
	i.appendChild(m);
	i.appendChild(n);
	h.appendChild(i);
}
addtablist();

//导入引导动画
function initloadingpic(){
	var h=document.createElement("div");
	h.id="loading";
	h.align="center";
	var i=document.createElement("img");
	i.src="/javascripts/dep_manage/images/loading.gif";
	var t=document.createElement("span");
	t.innerHTML="<br>正在载入...<br>请稍候";
	h.appendChild(i);
	h.appendChild(t);
	document.getElementById("tree").appendChild(h);
}
initloadingpic();
//删除引导动画
function delloadingpic(){
	var loading = document.getElementById("loading");
	if(loading!=null){
		loading.removeNode(true);
	}
}

//回到首页
function tofirst(){
	addtag("firstpage","首页","home.gif");
	switchtag("firstpage");
	var url = "inc/first.asp?timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handlefirstStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
	document.all.topoperation.innerHTML = "首页";
}

function handlefirstStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
		var ajaxRequestObj = xmlHttp.responseText;
		document.all.firstpage.innerHTML = ajaxRequestObj;
        }
    }
}
// TODO 添加时间
//tofirst();


//导入其他js文件
var head = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "/javascripts/dep_manage/dep.js";
head.appendChild(script);
script = document.createElement('script');
script.type = 'text/javascript';
script.src = "/javascripts/dep_manage/util.js";
head.appendChild(script);
script = document.createElement('script');
script.type = 'text/javascript';
script.src = "/javascripts/dep_manage/menu.js";
head.appendChild(script);
script = document.createElement('script');
script.type = 'text/javascript';
script.src = "/javascipts/dep_manage/weather.js";
head.appendChild(script);
